package controller_CoedAuto

import (
	"GA-SERVER/api/api_CodeAuto"
	"GA-SERVER/internal/controller/controller_CoedAuto/singleCrud"
	"context"
	"github.com/gogf/gf/v2/frame/g"
)

var CodeAuto guCodeAuto
type guCodeAuto struct {}
// 导航页导航按钮
func(gu guCodeAuto)Index(ctx context.Context,req *api_CodeAuto.CodeAutoIndexReq)(res *api_CodeAuto.CodeAutoIndexRes,err error){
	tpl := "internal/controller/controller_CoedAuto/singleCrud/template/home.html"
	singleCrudList := singleCrud.List()
	data := g.Map{
		"singleCrudList":singleCrudList,
	}
	err = g.RequestFromCtx(ctx).Response.WriteTpl(tpl,data)
	return
}

// 查询指定模块的和变量的代码
func(gu guCodeAuto)GetCode(ctx context.Context,req *api_CodeAuto.CodeAutoGetCodeReq)(res *api_CodeAuto.CodeAutoGetCodeRes,err error){
	reqData := g.RequestFromCtx(ctx)
	CodeType := reqData.Get("CodeType").String()
	CodeValue := reqData.Get("CodeValue").String()
	switch CodeType {
	case "singleCrud":
		// 单一数据curd
		err = singleCrud.Render(ctx,CodeValue)
		if err != nil {
			return nil, err
		}
	case "world":
		g.Dump("world")
	default:
		reqData.Response.Writeln("无效网址" + CodeType + "/" + CodeValue)
	}
	return
}
